package leetcode.hash.p387;

public class Solution_v1 {
    public int firstUniqChar(String s) {
        int[] counts = new int[26];
        for(int i = 0; i < s.length(); i++) {
            counts[s.charAt(i) - 'a']++;
        }
        
        for(int i = 0; i < s.length(); i++) {
            if(counts[s.charAt(i) - 'a'] == 1) {
                return i;
            }
        }
        return -1;
    }
    
    public static void main(String[] args) {
        Solution_v1 solution = new Solution_v1();
        System.out.println(solution.firstUniqChar("leetcode"));
        System.out.println(solution.firstUniqChar("loveleetcode"));
    }
}
